﻿using System;
using System.Collections.Generic;
using System.Text;
using NHibernate.Param;
using NHibernate.Type;
using System.Collections;

namespace Cms.BLL
{
    public class TabPage : BaseDao<Model.Sys_Tabpage, string>
    {
        /// <summary>
        /// 增
        /// </summary>
        /// <param name="model"></param>
        public void Add(Model.Sys_Tabpage model)
        {
            this.Save(model);
            this.CommitChanges();
        }
        //改
        public void Update(Model.Sys_Tabpage model)
        {
            this.SaveOrUpdate(model);
            this.CommitChanges();
        }
        //删
        public bool Delete(Model.Sys_Tabpage model)
        {
            bool result = this.Delete(model);
            this.CommitChanges();
            return result;
        }
        public List<Model.Sys_Tabpage> GetChilds(List<Model.Sys_Tabpage> list, string tabid)
        {
            List<Model.Sys_Tabpage> result = new List<Cms.Model.Sys_Tabpage>();
            foreach (Model.Sys_Tabpage m in list)
            {
                if (String.Compare(m.Parentid, tabid) == 0)
                {
                    result.Add(m);
                }
                else { 
                    if(String.IsNullOrEmpty(m.Parentid)&& String.IsNullOrEmpty(tabid))
                        result.Add(m);
                }
            }
            return result;
        }
        public List<Model.Sys_Tabpage> GetChilds(string TabID) {
            List<Model.Sys_Tabpage> result = new List<Cms.Model.Sys_Tabpage>();
            IList lp=new List<ParamInfo>();
            lp.Add(new ParamInfo("p",TabID,NHibernate.NHibernateUtil.String));
            result = (List<Model.Sys_Tabpage>)this.Find<Model.Sys_Tabpage>("from Sys_Tabpage where Parentid=:p", lp);
            return result;
        }

        public List<Model.Sys_Webpart> GetWebparts(string TabID) {
            List<Model.Sys_Webpart> result = new List<Cms.Model.Sys_Webpart>();
            IList lp = new List<ParamInfo>();
            lp.Add(new ParamInfo("TabID", TabID, NHibernate.NHibernateUtil.String));

            result = (List<Model.Sys_Webpart>)this.Find<Model.Sys_Webpart>("from Sys_Webpart where Id in (select Wpt_Id from Sys_Tab_Wpt where Tab_Id=:TabID)", lp);
            return result;
        }
        public List<Model.Sys_Tab_Wpt> GetWebpartExtInfo(string TabID) {
            List<Model.Sys_Tab_Wpt> result = new List<Cms.Model.Sys_Tab_Wpt>();
            IList lp = new List<ParamInfo>();
            lp.Add(new ParamInfo("TabID", TabID, NHibernate.NHibernateUtil.String));

            result = (List<Model.Sys_Tab_Wpt>)this.Find<Model.Sys_Tab_Wpt>("from Sys_Tab_Wpt where Tab_Id=:TabID", lp);
            return result;
        }
    }
}
